<template>
  <div class="register">
    <van-nav-bar title="面经注册" />
    <van-form class="register-main" @submit="onSubmit">
      <van-cell-group class="register-input" inset>
        <van-field
          v-model="username"
          label="用户名"
          colon
          name="username"
          placeholder="请输入用户名"
          :rules="[{ pattern: /^\w{6,10}/, message: '请输入6~10位字符' }]"
        />
        <van-field
          type="password"
          label="密 码"
          colon
          v-model="password"
          name="password"
          placeholder="请输入密码"
          :rules="[{ pattern: /^\w{8,12}/, message: '请输入8~12位字符' }]"
        />
      </van-cell-group>
      <van-button type="info">注册</van-button>
    </van-form>
    <div class="register-footer">
      <router-link to="/login">登录账号</router-link>
    </div>
  </div>
</template>

<script>
import {registerAPI} from "@/api/uesr";

export default {
  name: "App",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    async onSubmit(values) {
      // console.log("submit", values);
      // request({url:"/h5/user/register",method:"post",data:values})
      const result = await registerAPI(values);
      this.$toast.success(result.data.message);
      if (result.data.code === 10000) {
        setTimeout(() => {
          this.$router.push({ path: "/login" });
        }, 2000);
      }
    },
  },

  computed: {},

  components: {},

  beforeCreate() {},

  mounted() {},

  updated() {},

  watch: {},
};
</script>

<style scoped lang=less>
.register-main {
  display: flex;
  width: 320px;
  padding: 10px;
  margin: 0 auto;
  align-items: center;
  flex-direction: column;
  padding-top: 20px;

  .van-cell {
    background-color: rgb(242, 242, 242);
  }
  button {
    width: 100px;
    margin-top: 20px;
    height: 35px;
  }
}

.register-footer {
  display: flex;
  justify-content: flex-end;
  a {
    font-size: 12px;
    margin-right: 10px;
    color: #1989fa;
  }
}
</style>